Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents

Managing an Offscreen Graphics World's Pixel Image

Use the GetGWorldPixMap function to obtain a handle to the PixMap record for an offscreen graphics world. You can then pass this handle, which is of data type PixMapHandle , in parameters to several routines that allow you to manage an offscreen graphics world's pixel image.

To prevent the base address for an offscreen pixel image from being moved (while you draw into or copy from its pixel map, for example), pass its handle to the LockPixels function. When you are finished drawing into or copying from an offscreen pixel map, pass its handle to the UnlockPixels procedure.

You can use the AllowPurgePixels procedure to make the base address for an offscreen pixel image purgeable. To prevent the Memory Manager from purging the base address for an offscreen pixel map, use the NoPurgePixels procedure.

To save the current information about the memory allocated for an offscreen pixel image, you can use the GetPixelsState function. To restore this state, you can use the SetPixelsState procedure.

You can use the GetPixBaseAddr function to obtain a pointer to the beginning of a pixel image in memory. You can use the PixMap32Bit function to determine whether a pixel map requires 32-bit addressing mode for access to its pixel image.

GetGWorldPixMap

Use the GetGWorldPixMap function to obtain the pixel map created for an offscreen graphics world.

FUNCTION GetGWorldPixMap (offscreenGWorld: GWorldPtr):
                                          PixMapHandle;
offscreenGWorld
A pointer to an offscreen graphics world.

DESCRIPTION

The GetGWorldPixMap function returns a handle to the pixel map created for an offscreen graphics world. In the offscreenGWorld parameter, pass the pointer returned to your application by the NewGWorld function when you created the offscreen graphics world. Your application can, in turn, pass the handle returned by GetGWorldPixMap as a parameter to other QuickDraw routines that accept a handle to a pixel map.

On a system running only basic QuickDraw, the GetGWorldPixMap function returns the handle to a 1-bit pixel map that your application can supply as a parameter to the other routines related to offscreen graphics worlds. However, your application should not supply this handle to Color QuickDraw routines.

SPECIAL CONSIDERATIONS

To ensure compatibility on systems running basic QuickDraw instead of Color QuickDraw, use GetGWorldPixMap whenever you need to gain access to the bitmap created for a graphics world--that is, do not dereference the GWorldPtr record for that graphics world.

The GetGWorldPixMap function is not available in systems preceding System 7. You can make sure that the GetGWorldPixMap function is available by using the Gestalt function with the gestaltSystemVersion selector. Test the low-order word in the response parameter; if the value is $0700 or greater, then GetGWorldPixMap is available.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the GetGWorldPixMap function are

Trap macro

Selector

_QDExtensions

$00040017

SEE ALSO

The Gestalt function is described in the chapter "Gestalt Manager" of Inside Macintosh: Operating System Utilities .

LockPixels

To prevent the base address for an offscreen pixel image from being moved while you draw into or copy from its pixel map, use the LockPixels function.

FUNCTION LockPixels (pm: PixMapHandle): Boolean;
pm
A handle to an offscreen pixel map. To get a handle to an offscreen pixel map, use the GetGWorldPixMap function, described on GetGWorldPixMap .

DESCRIPTION

The LockPixels function prevents the base address for an offscreen pixel image from being moved. You must call LockPixels before drawing to or copying from an offscreen graphics world.

The baseAddr field of the PixMap record for an offscreen graphics world contains a handle instead of a pointer (which is what the baseAddr field for an onscreen pixel map contains). The LockPixels function dereferences the PixMap handle into a pointer. When you use the UnlockPixels procedure, which is described next, the handle is recovered.

If the base address for an offscreen pixel image hasn't been purged by the Memory Manager or is not purgeable, LockPixels returns TRUE as its function result, and your application can draw into or copy from the offscreen pixel map. However, if the base address for an offscreen pixel image has been purged, LockPixels returns FALSE to indicate that you can perform no drawing to or copying from the pixel map. At that point, your application should either call the UpdateGWorld function (described on UpdateGWorld ) to reallocate the offscreen pixel image and then reconstruct it, or draw directly in a window instead of preparing the image in an offscreen graphics world.

As soon as you are finished drawing into and copying from the offscreen pixel image, you should call the UnlockPixels procedure.

SPECIAL CONSIDERATIONS

The LockPixels function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the LockPixels function are

Trap macro

Selector

_QDExtensions

$00040001

SEE ALSO

Listing 6-1 and Listing 6-2 illustrate the use of this function. See Inside Macintosh: Memory for more information about memory management.

UnlockPixels

When you are finished drawing into and copying from an offscreen graphics world, use the UnlockPixels procedure.

PROCEDURE UnlockPixels (pm: PixMapHandle);
pm
A handle to an offscreen pixel map. Pass the same handle that you passed previously to the LockPixels function.

DESCRIPTION

The UnlockPixels procedure allows the Memory Manager to move the base address for the offscreen pixel map that you specify in the pm parameter. To ensure the integrity of the data in a pixel image, call LockPixels (explained in the preceding section) before drawing into or copying from a pixel map; then, to prevent heap fragmentation, call UnlockPixels as soon as your application finishes drawing to and copying from the offscreen pixel map.

The baseAddr field of the PixMap record for an offscreen graphics world contains a handle instead of a pointer (which is what the baseAddr field for an onscreen pixel map contains). The LockPixels function dereferences the PixMap handle into a pointer. When you use the UnlockPixels procedure, the handle is recovered.

You don't need to call UnlockPixels if LockPixels returns FALSE , because LockPixels doesn't lock the memory for a pixel image if that memory has been purged. However, calling UnlockPixels on purged memory does no harm.

SPECIAL CONSIDERATIONS

The UnlockPixels procedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the UnlockPixels procedure are

Trap macro

Selector

_QDExtensions

$00040002

AllowPurgePixels

You can use the AllowPurgePixels procedure to make the base address for an offscreen pixel image purgeable.

PROCEDURE AllowPurgePixels (pm: PixMapHandle);
pm
A handle to an offscreen pixel map.

DESCRIPTION

The AllowPurgePixels procedure marks the base address for an offscreen pixel image as purgeable; this allows the Memory Manager to free the memory it occupies if available memory space becomes low. By default, NewGWorld creates an unpurgeable base address for an offscreen pixel image.

To get a handle to an offscreen pixel map, first use the GetGWorldPixMap function, described on GetGWorldPixMap . Then supply this handle for the pm parameter of AllowPurgePixels .

Your application should call the LockPixels function (described on LockPixels ) before drawing into or copying from an offscreen pixel map. If the Memory Manager has purged the base address for its pixel image, LockPixels returns FALSE . In that case either your application should use the UpdateGWorld function (described on UpdateGWorld ) to begin reconstructing the offscreen pixel image, or it should draw directly to an onscreen graphics port.

Only unlocked memory blocks can be made purgeable. If you use LockPixels , you must use the UnlockPixels procedure (explained in the preceding section) before calling AllowPurgePixels .

SPECIAL CONSIDERATIONS

The AllowPurgePixels procedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the AllowPurgePixels procedure are

Trap macro

Selector

_QDExtensions

$0004000B

SEE ALSO

See Inside Macintosh: Memory for more information about memory management.

NoPurgePixels

To prevent the Memory Manager from purging the base address for an offscreen pixel image, use the NoPurgePixels procedure.

PROCEDURE NoPurgePixels (pm: PixMapHandle);
pm
A handle to an offscreen pixel map.

DESCRIPTION

The NoPurgePixels procedure marks the base address for an offscreen pixel image as unpurgeable. To get a handle to an offscreen pixel map, use the GetGWorldPixMap function, described on GetGWorldPixMap . Then supply this handle for the pm parameter of NoPurgePixels .

SPECIAL CONSIDERATIONS

The NoPurgePixels procedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the NoPurgePixels procedure are

Trap macro

Selector

_QDExtensions

$0004000C

GetPixelsState

To save the current information about the memory allocated for an offscreen pixel image, you can use the GetPixelsState function.

FUNCTION GetPixelsState (pm: PixMapHandle): GWorldFlags;
pm
A handle to an offscreen pixel map.

DESCRIPTION

The GetPixelsState function returns information about the memory allocated for the base address for an offscreen pixel image. This information can be either of the following flags defined by the GWorldFlags data type:

TYPE GWorldFlags =
SET OF (            {flags for GetPixelsState only are listed here}
    pixelsPurgeable,        {the base address for an offscreen pixel }
                            { image is purgeable}
    pixelsLocked,           {the offscreen pixel image is locked and }
                            { not purgeable}
);

If the pixelsPurgeable flag is not returned, then the base address for the offscreen pixel image is unpurgeable. If the pixelsLocked flag is not returned, then the base address for the offscreen pixel image is unlocked.

After using GetPixelsState to save this state information, your application can later use the SetPixelsState procedure, described next, to restore this state to the offscreen graphics world.

Specify a handle to a pixel map in the pm parameter. To get a handle to an offscreen pixel map, use the GetGWorldPixMap function, described on GetGWorldPixMap .

SPECIAL CONSIDERATIONS

The GetPixelsState function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the GetPixelsState function are

Trap macro

Selector

_QDExtensions

$0004000D

SEE ALSO

After using GetPixelsState and before using SetPixelsState , your application can temporarily use the AllowPurgePixels procedure (described on AllowPurgePixels ) to make the base address for an offscreen pixel image purgeable, the NoPurgePixels procedure (described on NoPurgePixels ) to make it unpurgeable, the LockPixels function (described on LockPixels ) to prevent it from being moved, and the UnlockPixels procedure (described on UnlockPixels ) to allow it to be moved.

SetPixelsState

To restore an offscreen pixel image to the state that you saved with the GetPixelsState function (explained in the preceding section), you can use the  SetPixelsState procedure.

PROCEDURE SetPixelsState (pm: PixMapHandle; state: GWorldFlags);
pm
A handle to an offscreen pixel map.
state
Flags, which you usually save with the GetPixelsState function, defined by the GWorldFlags data type:
             TYPE GWorldFlags =
             SET OF ( {flags for SetPixelsState are listed here}
                 pixelsPurgeable,        {make the base address for an }
                                        { offscreen pixel image purgeable}
                 pixelsLocked            {prevent the base address for an }
                                        { offscreen pixel image from }
                                        { being moved}
             );

DESCRIPTION

The SetPixelsState procedure changes the state of the memory allocated for an offscreen pixel image to the state indicated by the flags specified in the state parameter, which you typically save using the GetPixelsState function.

Because only an unlocked memory block can be purged, SetPixelsState calls the UnlockPixels and AllowPurgePixels procedures (described on UnlockPixels and AllowPurgePixels , respectively) if the state parameter specifies the pixelsPurgeable flag. If the state parameter does not specify the pixelsPurgeable flag, SetPixelsState makes the base address for the offscreen pixel image unpurgeable.

If the state parameter does not specify the pixelsLocked flag, SetPixelsState allows the base address for the offscreen pixel image to be moved.

SPECIAL CONSIDERATIONS

The SetPixelsState procedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the SetPixelsState procedure are

Trap macro

Selector

_QDExtensions

$0008000E

SEE ALSO

After using GetPixelsState and before using SetPixelsState , your application can temporarily alter the offscreen graphics world by using the AllowPurgePixels procedure (described on AllowPurgePixels ) to temporarily mark the memory block for its offscreen pixel map as purgeable, the NoPurgePixels procedure (described on NoPurgePixels ) to make it unpurgeable, the LockPixels function (described on LockPixels ) to prevent it from being moved, and the UnlockPixels procedure (described on UnlockPixels ) to unlock it.

GetPixBaseAddr

You can use the GetPixBaseAddr function to obtain a pointer to an offscreen pixel map.

FUNCTION GetPixBaseAddr (pm: PixMapHandle): Ptr;
pm
A handle to an offscreen pixel map. To get a handle to an offscreen pixel map, use the GetGWorldPixMap function, described on GetGWorldPixMap .

DESCRIPTION

The GetPixBaseAddr function returns a 32-bit pointer to the beginning of a pixel image. The baseAddr field of the PixMap record for an offscreen graphics world contains a handle instead of a pointer, which is what the baseAddr field for an onscreen pixel map contains. You must use the GetPixBaseAddr function to obtain a pointer to the PixMap record for an offscreen graphics world.

Your application should never directly access the baseAddr field of the PixMap record for an offscreen graphics world; instead, your application should always use GetPixBaseAddr . If your application is using 24-bit mode, your application should then use the PixMap32Bit function (described next) to determine whether a pixel map requires 32-bit addressing mode for access to its pixel image.

If the offscreen buffer has been purged, GetPixBaseAddr returns NIL .

SPECIAL CONSIDERATIONS

Any QuickDraw routines that your application uses after calling GetPixBaseAddr may change the base address for the offscreen pixel image.

The GetPixBaseAddr function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the GetPixBaseAddr function are

Trap macro

Selector

_QDExtensions

$0004000F

SEE ALSO

See Inside Macintosh: Memory for information about determining addressing modes.

PixMap32Bit

You can use the PixMap32Bit function to determine whether a pixel map requires 32-bit addressing mode for access to its pixel image.

FUNCTION PixMap32Bit (pmHandle: PixMapHandle): Boolean;
pmHandle
A handle to an offscreen pixel map.

DESCRIPTION

The PixMap32Bit function returns TRUE if a pixel map requires 32-bit addressing mode for access to its pixel image. If your application is in 24-bit mode, you must change to 32-bit mode.

To get a handle to an offscreen pixel map, first use the GetGWorldPixMap function, described on GetGWorldPixMap . Then supply this handle for the pm parameter of PixMap32Bit .

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the PixMap32Bit function are

Trap macro

Selector

_QDExtensions

$00040016

SEE ALSO

See Inside Macintosh: Memory for information about determining and setting addressing modes.

 


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents